<?php
class Slog_Applications
{
	static protected $_instance;
	
	protected $apps;
	
	public function __construct()
	{
		$this->apps = array();
	}
	
	/**
	 * @return	Slog_Applications
	 */
	static public function getInstance()
	{
		return self::$_instance ? self::$_instance : (self::$_instance = new self());
	}
	
	public function add($appdir)
	{
		if (strpos($appdir, '/') === false) {
			$this->add(SLOGGY_DIR . '/apps/' . $appdir);
			$this->add(SITE_DIR . '/apps/' . $appdir);
		}
		
		if (is_file($appdir) && !in_array($appdir, $this->apps)) {
			// Añadimos la aplicación a la lista
			$this->apps[] = $appdir;
			// Ejecutamos su boot
			$boot = $appdir . '/lib/boot.php';
			if (is_file($boot)) {
				require $boot;
			}
			return true;
		}
		return false;
	}
}

/**
 * 
 * @return	Slog_Applications
 */
function applications()
{
	return Slog_Applications::getInstance();
}
